package API;
//本类用于练习字符串的拼接
public class TestString3 {

    public static void main(String[] args) {//将26个字母拼接一万次
        String s = "abcdefghijklmnopqrstuvwxyz";
//        String static1 = "";
//        for (int i = 0; i <10000 ; i++) {
//            s1 =s1 + s.concat(s);
//        }
//        System.out.println(s1);
//        method1(s);
        methond(s);
    }

    private static void methond(String s) {
        //创建工具类对象
        StringBuffer sb = new StringBuffer();
        StringBuilder sb2 = new StringBuilder();
        //拼接一万次
        long t1 = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
//            sb2.append(s);
            sb.append(s);
        }
        long t2 = System.currentTimeMillis();
        System.out.println(sb2);
        System.out.println(t2-t1);
    }

    private static void method1(String s) {//first
        String result = "";
        //获取循环开始的系统当前时间
        long t1 = System.currentTimeMillis();
        for (int i = 0; i <10001 ; i++) {
            result = result + s;

        }
        //获取循环拼接之后的系统的当前时间
        long t2 = System.currentTimeMillis();
        System.out.println(result);
        System.out.println(t2-t1);
    }//8.12pm 80
}
